import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

import Mobile from '@/view/Mobile';
import MobileHome from '@/view/mobile/MobileHome';
import MobilePerson from '@/view/mobile/MobilePerson';
import MobileBooksList from '@/view/mobile/MobileBooksList';
import MobileBookShelf from '@/view/mobile/MobileBookShelf';
import MobileBookDetail from '@/view/mobile/MobileBookDetail';
import MobileHeader from '@/components/mobile/default/MobileHeader';
import MobileFooter from '@/components/mobile/default/MobileFooter';
import MobileOrdersHead from '@/components/mobile/bookshelf/MobileOrdersHead';
import MobileOrders from '@/components/mobile/bookshelf/MobileOrders';
import MobileOrders1 from '@/components/mobile/bookshelf/MobileOrders1';
import MobileOrders2 from '@/components/mobile/bookshelf/MobileOrders2';
import MobileOrders3 from '@/components/mobile/bookshelf/MobileOrders3';

import Pc from '@/view/Pc';
import PcHome from '@/view/pc/PcHome';
import PcHeader from '@/components/pc/home/HomeHeader';
import PcFooter from '@/components/pc/home/HomeFooter';
import PcUpdate from '@/components/pc/update/Update';
import PcUpdatePic from '@/components/pc/update/UpdatePic';
import PcUpdatePwd from '@/components/pc/update/UpdatePwd';
import PcUpdateUser from '@/components/pc/update/UpdateUser';
import PcBooksList from '@/view/pc/PcBooksList';
import PcMyCart from '@/view/pc/PcMyCart';
import PcGoPlace from '@/view/pc/PcGoPlace.vue';
import PcOrder from '@/view/pc/PcOrder.vue';
import PcBookDetail from '@/view/pc/PcBookDetail';
import PcPayment from '@/view/pc/PcPayment';
import PcRegister from '@/view/pc/PcRegister';
import UserLogin from '@/components/user/UserLogin';
import MobileSearch from '@/view/mobile/MobileSearch';

import BackendManage from '@/view/BackendManage.vue'
import HotPicturc from '@/view/manage/hotPicturc/HotPicturc.vue'
import AddUpdateHotPicturc from '@/view/manage/hotPicturc/AddUpdateHotPicturc.vue'
import OneAdmin from '@/view/manage/typeAdmin/OneAdmin.vue'
import TwoAdmin from '@/view/manage/typeAdmin/TwoAdmin.vue'
import CommodityList from '@/view/manage/commodityManage/CommodityList.vue'
import AddUpateCommodity from '@/view/manage/commodityManage/AddUpateCommodity.vue'
import QueryDetails from '@/view/manage/queryManage/QueryDetails.vue'
import {
	store
} from 'core-js/modules/_wks';



const routes = [{
		path: '/',
		redirect: {
			// name: PcHome
			name: Mobile
		}
	},
	{
		path: '/pc',
		name: Pc,
		component: Pc,
		children: [{
				path: 'home',
				name: PcHome,
				meta: {
					title: '首页',
				},
				components: {
					default: PcHome,
					header: PcHeader,
					footer: PcFooter
				}
			},
			{
				path: 'booklist',
				name: PcBooksList,
				meta: {
					title: '精选',
				},
				components: {
					default: PcBooksList,
					header: PcHeader,
					footer: PcFooter
				}
			},
			{
				path: 'bookdetail/:bookid',
				name: PcBookDetail,
				meta: {
					title: '书籍详情',
				},
				components: {
					default: PcBookDetail,
					header: PcHeader,
					footer: PcFooter
				}
			},
			{
				path: 'mycart',
				name: PcMyCart,
				meta: {
					title: '购物车',
					isAuth: true
				},
				components: {
					default: PcMyCart,
					header: PcHeader,
					footer: PcFooter
				}
			},
			{
				path: 'goplace',
				name: PcGoPlace,
				meta: {
					title: '确认订单',
					isAuth: true
				},
				components: {
					default: PcGoPlace,
					header: PcHeader,
					footer: PcFooter
				}
			},
			{
				path: 'order',
				name: PcOrder,
				meta: {
					title: '订单列表',
					isAuth: true
				},
				components: {
					default: PcOrder,
					header: PcHeader,
					footer: PcFooter
				}
			},
			{
				path: 'payment',
				name: PcPayment,
				meta: {
					title: '支付',
				},
				components: {
					default: PcPayment,
					header: PcHeader,
					footer: PcFooter
				}
			},
			{
				path: 'register',
				name: PcRegister,
				meta: {
					title: '注册页面',
				},
				components: {
					default: PcRegister,
					header: PcHeader,
					footer: PcFooter
				}
			},
			{
				path: 'update',
				name: PcUpdate,
				meta: {
					title: '个人信息',
					isAuth: true
				},
				components: {
					default: PcUpdate,
					header: PcHeader,
					footer: PcFooter
				},
				children: [{
						path: 'updateuser',
						name: PcUpdateUser,
						meta: {
							title: '修改个人信息',
						},
						component: PcUpdateUser
					},
					{
						path: 'updatepic',
						name: PcUpdatePic,
						meta: {
							title: '修改头像',
						},
						component: PcUpdatePic
					},
					{
						path: 'updatepwd',
						name: PcUpdatePwd,
						meta: {
							title: '修改密码',
						},
						component: PcUpdatePwd
					}
				]
			},
		]
	},
	{
		path: '/mobile',
		name: Mobile,
		meta: {
			title: '首页'
		},
		component: Mobile,
		children: [{
				path: 'home',
				name: MobileHome,
				meta: {
					title: '首页'
				},
				components: {
					default: MobileHome,
					header: MobileHeader,
					footer: MobileFooter
				}
			},
			{
				path: 'person',
				name: MobilePerson,
				meta: {
					title: '个人'
				},
				components: {
					default: MobilePerson,
					header: MobileHeader,
					footer: MobileFooter
				}
			},
			{
				path: 'booklist',
				name: MobileBooksList,
				meta: {
					title: '精选'
				},
				components: {
					default: MobileBooksList,
					header: MobileHeader,
					footer: MobileFooter
				}
			},
			{
				path: 'bookshelf',
				name: MobileBookShelf,
				meta: {
					title: '书架'
				},
				components: {
					default: MobileBookShelf,
					header: MobileHeader,
					footer: MobileFooter
				}
			},
			{
				path: 'bookdetail/:bookid',
				name: MobileBookDetail,
				meta: {
					title: '详情'
				},
				component: MobileBookDetail
			},
		]
	}, {
		path: '/mobile/search',
		name: MobileSearch,
		meta: {
			title: '搜索'
		},
		component: MobileSearch
	}, {
		path: '/mobile',
		name: Mobile,
		meta: {
			title: '首页'
		},
		component: Mobile,
		children: [{
				path: 'orders',
				name: MobileOrders,
				meta: {
					title: '全部订单'
				},
				components: {
					default: MobileOrders,
					header: MobileOrdersHead,
				}
			},
			{
				path: 'orders1',
				name: MobileOrders1,
				meta: {
					title: '待付款'
				},
				components: {
					default: MobileOrders1,
					header: MobileOrdersHead,
				}
			},
			{
				path: 'orders2',
				name: MobileOrders2,
				meta: {
					title: '待发货'
				},
				components: {
					default: MobileOrders2,
					header: MobileOrdersHead,
				}
			},
			{
				path: 'orders3',
				name: MobileOrders3,
				meta: {
					title: '待收货'
				},
				components: {
					default: MobileOrders3,
					header: MobileOrdersHead,
				}
			},
		]
	}, {
		path: '/login',
		name: UserLogin,
		meta: {
			title: '登录页'
		},
		component: UserLogin
	},
	{
		path:'/backendManage',
		name:'BackendManage',
		meta: {
			title: '后台管理'
		},
		component:BackendManage,
		children:[
			{
				path:'hotPicturc',
				name:'HotPicturc',
				meta: {
					title: '热点图片'
				},
				component:HotPicturc,
			},
			{
				path:'addUpdateHotPicturc',
				name:'AddUpdateHotPicturc',
				meta: {
					title: '添加热点图片'
				},
				component:AddUpdateHotPicturc,
			},
			{
				path:'oneAdmin',
				name:'OneAdmin',
				meta: {
					title: '一级类型'
				},
				component:OneAdmin,
			},
			{
				path:'twoAdmin',
				name:'TwoAdmin',
				meta: {
					title: '二级类型'
				},
				component:TwoAdmin,
			},
			{
				path:'commodityList',
				name:'CommodityList',
				meta: {
					title: '商品列表'
				},
				component:CommodityList,
			},
			{
				path:'addUpateCommodity',
				name:'AddUpateCommodity',
				meta: {
					title: '添加商品'
				},
				component:AddUpateCommodity,
			},
			{
				path:'queryDetails',
				name:'QueryDetails',
				meta: {
					title: '订单详情'
				},
				component:QueryDetails,
			},
		]	
	}
];

const router = new VueRouter({
	routes
})

router.afterEach((to) => {
	document.title = to.meta.title;
})

router.beforeEach((to, from, next) => {
	if (to.meta.isAuth) {
		console.log(window.localStorage.getItem('token'))
		if (window.localStorage.getItem('token') != null) {
			next();
		} else {
			Vue.prototype.$message.error('抱歉，您无权限查看！请登录');
		}
	} else {
		next()
	}
})

export default router;